import gtk

class MailDialog(gtk.Dialog):
    LAST_RECIPIENT = ''
    
    def __init__(self, header):
        # Construct superclass.
        gtk.Dialog.__init__(self, header)
        
        # Add widgets.
        self.add_button(gtk.STOCK_CANCEL, 0)
        self.add_button(gtk.STOCK_OK, 1)

        hbox = gtk.HBox()
        left_vbox = gtk.VBox(True)
        right_vbox = gtk.VBox(True)
        hbox.pack_start(left_vbox)
        hbox.pack_start(right_vbox)
        left_vbox.pack_start(gtk.Label('Recipient:'))
        left_vbox.pack_start(gtk.Label('Subject:'))
        self.recipient = gtk.Entry()
        self.recipient.set_text(MailDialog.LAST_RECIPIENT)
        self.subject = gtk.Entry()
        right_vbox.pack_start(self.recipient)
        right_vbox.pack_start(self.subject)
        self.vbox.pack_start(hbox)
        
    def do_it(self):
        self.show_all()
        rc = self.run()
        self.hide_all()
        if rc == 1:
            # Ok button was clicked. Return the value given by the scale.
            MailDialog.LAST_RECIPIENT = self.recipient.get_text()
            return (self.recipient.get_text(), self.subject.get_text())
        else:
            # Cancel was clicked. Return an error indicator.
            return None
